﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Diagnostics;
using System.IO;

namespace DatabaseEntegreItri.Utils
{
    public class WindowUtils
    {
        public static Point getChildLocationInRightSide(Window parent,Size childSize) {

            double left = 0;
            double top = 0;
            int screenUsableWidth = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width;
            int screenHeight = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height;
            if (parent.Left + parent.Width + childSize.Width > screenUsableWidth)
            {                
                left = parent.Left - childSize.Width;
                if (left < 0) {
                    left = 0;
                }
            }
            else {

                left = parent.Left + parent.Width;            
            }
            if (parent.Top < 0) {
                top = 0;
            }
            else if (parent.Top + childSize.Height > screenHeight)
            {
                top = screenHeight - childSize.Height;
            }
            else
            {
                top = parent.Top;
            }
            return new Point(left,top); 
        }
        public static int deneme() {

            return -1;
        }
        public static bool isDebug() {


            Process x = Process.GetCurrentProcess();
            if (!(x.ProcessName.Contains("vshost") || x.ProcessName.Contains("devenv")))//Debug mode
            {
                return false;
                
            }
            else
            {

                return true;
            }

        }
        public static String getFileShortened(String fileName)
        {
            FileInfo fi = new FileInfo(fileName);
            if (fi.Directory.ToString().Split('\\').Length > 2)
            {
                return fi.Directory.Root + "...\\" + fi.Name;
            }
            else
            {
                return fi.FullName;
            }
        }
        public static String getDBFile(String definedName, String ext)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.FileName = definedName; // Default file name
            dlg.DefaultExt = "." + ext; // Default file extension
            dlg.Filter = "Database Documents (." + ext + ")|*." + ext; // Filter files by extension
            // Show open file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process open file dialog box results
            if (result == true)
            {
                string filename = dlg.FileName;
                return filename;

            }
            else return null;
        }
        public static double timeStringToDouble(String time)
        {

            string[] splittedTime = time.Split(':');
            double totalTime = 0;
            int multi = (int)Math.Pow(60, splittedTime.Length - 1);
            foreach (String str in splittedTime)
            {

                totalTime += multi * (Convert.ToInt32(str));

                multi /= 60;
            }
            return totalTime;
        }
    
    }
}
